using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MimeCloud.AssetManagement.Business.Interface;
using MimeCloud.AssetManagement.ProviderServices;

namespace MimeCloud.AssetManagement.Editor
{
    public class AppCommon
    {
        public static AppCommon _current;
        public static AppCommon Current
        {
            get
            {
                if (_current==null)
                    _current = new AppCommon();
                return _current;
            }
        }

        public AppCommon()
        {
            ReloadData();
        }

        public IList<IAssetContentType> AllAssetContentTypes { get; set; }
        public IList<IMimeType> AllMimeTypes { get; set; }
        public IList<ILanguage> AllLanguages { get; set; }
        public IList<IMetaKey> AllMetadataKeys { get; set; }
        public IList<IRepository> AllRepositories { get; set; }

        public ILanguage DefaultLanguage
        {
            get
            {
                return (from lang in AllLanguages where lang.LanguageCode == "sys" select lang).First();
            }
        }
        public IList<ILanguage> EnabledLanguages
        {
            get
            {
                return (from lang in AllLanguages where lang.Enabled select lang).ToList();
            }
        }
        public void ReloadData()
        {
            AllAssetContentTypes = AssetManagerConfig.GetAssetReaderProvider().GetAllAssetContentType();
            AllMimeTypes = AssetManagerConfig.GetAssetReaderProvider().GetAllMimeType();
            AllLanguages = AssetManagerConfig.GetAssetReaderProvider().GetAllLanguage();
            AllMetadataKeys = AssetManagerConfig.GetAssetReaderProvider().GetAllMetaKey();
            AllRepositories = AssetManagerConfig.GetAssetReaderProvider().GetAllRepository();
        }
    }
}
